package com.snail.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.snail.model.pojo.cart.BizCartItem;
import com.snail.model.vo.cart.BizProductSkuVo;
import com.snail.model.vo.cart.CartItemGroupBySellerVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BizCartItemMapper extends BaseMapper<BizCartItem> {

    // BizCartItemMapper 补充方法：查询购物车中的商品项
    @Select("SELECT * FROM biz_cart_item WHERE cart_id = #{cartId} AND product_id = #{productId}")
    BizCartItem selectByCartIdAndProductId(Integer cartId, Integer productId);


    //删除购物车中的商品项
    @Delete("DELETE FROM biz_cart_item WHERE cart_id = #{cartId} AND product_id = #{productId}")
    void deleteByCartIdAndProductId(Integer cartId, Integer productId);

    //清空购物车
    @Delete("DELETE FROM biz_cart_item WHERE cart_id = #{cartId}")
    void deleteByCartId(Integer cartId);

    /**
     * 根据用户 ID 查询购物车商品并按商家 ID 分组
     * @param userId 当前登录用户 ID
     * @return 按商家分组的购物车商品 VO 列表
     */
    List<CartItemGroupBySellerVO> listCartItemGroupBySeller(Long userId);

//新增数据到购物车项表
    @Insert("INSERT INTO biz_cart_item (cart_id, product_id, seller_user_id, quantity, selected, price, specs, product_name) " +
            "VALUES (#{cartId}, #{productId}, #{sellerUserId}, #{quantity}, #{selected}, #{price}, #{specs}, #{productName})")
    void insertCartItem(BizCartItem bizCartItem);

}
